<template>
<h2>添加会员等级权益</h2>
<table border="1">
    <tr>
        <td>会员等级</td>
        <td>
            <select v-model="RankRight.Rank_Id">
                <option :value="0">请选择</option>
                <option :value="i.Rank_Id" v-for="i in rank">{{i.Rank_Name}}</option>
            </select>
        </td>
    </tr>

    <tr>
        <td>会员权益</td>
        <td>
            <select v-model="RankRight.MR_Id">
                <option :value="0">请选择</option>
                <option :value="i.MR_Id" v-for="i in right">{{i.MR_Name}}</option>
            </select>
        </td>
    </tr>

    <tr>
        <td colspan="2">
            <input type="button" value="添加" @click="AddRankRight"/>
        </td>
    </tr>

</table>


</template>

<script setup lang="ts">

import {ref,onMounted} from'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
const router=useRouter();

onMounted(()=>{
    GetRank();
    GetRight();
})

//保存会员等级信息
const rank=ref([{
    Rank_Id:0,
    Rank_Name:""
}])

//保存权益信息
const right=ref([{
    MR_Id:0,
    MR_Name:""
}])

//加载会员等级
const GetRank=()=>{
    axios.get("https://localhost:7153/api/Member/ShowRankInfo/ShowRankInfo")
    .then(res=>{
        rank.value=res.data;
        // console.log(rank.value)
    })
    .catch(err=>{
        alert(err);
    })
}

//加载会员权益
const GetRight=()=>{
    axios.get("https://localhost:7153/api/Member/ShowRightsInfo/ShowRightsInfo")
    .then(res=>{
        right.value=res.data;
        console.log(res.data)
        console.log(right.value)
    })
    .catch(err=>{
        alert(err);
    })
}

const RankRight=ref({
    MR_Id:0,
    Rank_Id:0
})

const AddRankRight=()=>{
    axios.post("https://localhost:7153/api/Member/AddRankRights/AddRankRights",RankRight.value)
    .then(res=>{
        if(res.data==-1){
            alert('数据存在不能继续添加');
        }
        else if(res.data>0){
            alert('添加成功');
        }
        else{
            alert('添加失败');
        }
    })
    .catch(err=>{
        alert(err);
    })
}



</script>
